package c570a1

class BookService {
	boolean transactional = false
    def getStaticBook() {
	return new Book(author: "Tracy Kidder",title: "The Soul of a New Machine", ISBN: "34593459038")
    }

	def getRandomBook() {
	def allBooks = c570a1.Book.list()
	def randomBook = null
	if (allBooks.size() > 0){
		def randomIdx = new Random().nextInt(allBooks.size())
		randomBook = allBooks[randomIdx]

}
	else {
		randomBook = getStaticBook()
	}
	return randomBook
}
}

